package com.bridge.controller;

import com.bridge.mapper.UserMapper;
import com.bridge.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {
	
	@Resource
	private UserMapper userMapper;
	
	@GetMapping("/getUsers")
	public List<User> getUsers() {
		List<User> users=userMapper.getAll();
		return users;
	}
	
    @GetMapping("/getUser")
    public User getUser(Long id) {
    	User user=userMapper.getOne(id);
        return user;
    }
    
    @PostMapping("/add")
    public void save(User user) {
    	userMapper.insert(user);
    }
    
    @PostMapping(value="update")
    public void update(User user) {
    	userMapper.update(user);
    }
    
    @GetMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
    	userMapper.delete(id);
    }
    
    
}